#include "GreedyAlgorithm.h"
#include <iostream>

void GreedyAlgorithm::AddMorePoint()
{
	if (m_addStep == 0)
	{
		//add point
		for (int i=0;i<MAX_H;i++)
		for (int j=0;j<MAX_V;j++)
		{
			if ((i+j) % 5 == 2)
			{
				#if ENABLE_LOG	
				std::cout << "p:" << i <<":"<<j<<std::endl;
				#endif
				AddPoint(Point(i,j));
			}
		}
	}
	else if (m_addStep == 1)
	{
		for (int i=0;i<MAX_H;i++)
		for (int j=0;j<MAX_V;j++)
		{
			if ((i + j) % 5 == 4 &&  m_battle->IsUnkown(Point(i,j)))
			{
				#if ENABLE_LOG	
				std::cout << "p:" << i <<":"<<j<<std::endl;
				#endif
				AddPoint(Point(i,j));
			}
		}
	}
	else if (m_addStep == 2)
	{
		//old style
		for (int i=0;i<MAX_H;i++)
		for (int j=0;j<MAX_V;j++)
		{
			if ((i + j) % 5 == 0 &&  m_battle->IsUnkown(Point(i,j)))
			{
				#if ENABLE_LOG	
				std::cout << "p:" << i <<":"<<j<<std::endl;
				#endif
				AddPoint(Point(i,j));
			}
		}
		#if ENABLE_LOG	
		std::cout << "size:" << m_checkPoint.size() << std::endl;
		#endif

	}

	m_addStep++;
}

void GreedyAlgorithm::FoundShip(ShipPtr ship)
{
	Mod3Algorithm::FoundShip(ship);
	//check if found 5, then add more point
	if (m_maxLength < 5 && m_addStep < 2)
	{
		AddMorePoint();
	}
}

//init
void GreedyAlgorithm::Initialize(BattleShipPtr battle)
{
	Mod3Algorithm::Initialize(battle);
	for (int i=0; i < MAX_H; i++)
	for (int j=0; j < MAX_V; j++)
	{
		m_left[i][j] = j;
		m_right[i][j] = 9 - j;
		m_top[i][j] = i;
		m_bottom[i][j] = 9 - i;
	}
}
//end

//found a pos
void GreedyAlgorithm::FoundPos(Point p, bool value)
{
	Mod3Algorithm::FoundPos(p,value);
}